﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DRHotel_v1.Classes.DBManagers
{
    class ReportDBManager
    {
        public static ArrayList GetTotalNumOfRooms()
        {
            ArrayList Report = new ArrayList();
            try
            {
                //1. Connect to the database
                SqlConnection conn = new SqlConnection();
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["DRHotel_v1.Properties.Settings.DRHotelMngSysConnectionString1"].ConnectionString;
                conn.Open();
                //2. Prepare SQL Statement
                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = "SELECT * FROM Room";
                //4. Execute the SQL statement
                SqlDataReader dr = comm.ExecuteReader();
                //5. Fetch and process the result
                while (dr.Read())
                {
                    Report r = new Report();
                    r.RoomID = (int)dr["roomID"];
                    Report.Add(r);
                }
                //6. Close the connections
                dr.Close();
                conn.Close();
            }
            catch (SqlException e)
            {
                throw e;
            }

            return Report;
        }

        public static ArrayList GetTotalNumOfOccupiedRooms(string roomStatus)
        {
            ArrayList Report = new ArrayList();
            try
            {
                //1. Connect to the database
                SqlConnection conn = new SqlConnection();
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["DRHotel_v1.Properties.Settings.DRHotelMngSysConnectionString1"].ConnectionString;
                conn.Open();
                //2. Prepare SQL Statement
                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = "SELECT roomStatus FROM Room WHERE roomStatus= @roomStatus";
                comm.Parameters.AddWithValue("@roomStatus", roomStatus);
                //4. Execute the SQL statement
                SqlDataReader dr = comm.ExecuteReader();
                //5. Fetch and process the result
                while (dr.Read())
                {
                    Report r = new Report();
                    r.RoomStatus = (string)dr["roomStatus"];
                    Report.Add(r);
                }
                //6. Close the connections
                dr.Close();
                conn.Close();
            }
            catch (SqlException e)
            {
                throw e;
            }

            return Report;
        }


    }
}
